package com.heima.wemedia.listener;

import com.heima.model.wemedia.pojos.WmNews;
import com.heima.wemedia.service.AutomaticNewsReview;
import com.heima.wemedia.service.IWmNewsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @author 21236
 */
@Component
@Slf4j
public class TaskListener {

    @Autowired
    private AutomaticNewsReview automaticNewsReview;

    @Autowired
    private IWmNewsService wmNewsService;

    @KafkaListener(topics = "TASK_EXEC")
    public void doNewsTask(String message) {
        log.info("接收到发布文章任务消息");
        WmNews news = wmNewsService.getById(Long.parseLong(message));
        automaticNewsReview.saveToApp(news);
    }
}
